package cn.oms.oms.controller;


import cn.oms.oms.entity.Emr;
import cn.oms.oms.service.IEmrService;
import cn.oms.oms.vo.EMRVo;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author AllenChen曾晨
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/oms/emr")
@Slf4j
public class EmrController {

    @Autowired
    public IEmrService emrService;

    /**
     * 根据查询条件查询电子病历列表
     * @param emrVo
     * @return
     */
    @PostMapping("/selectEMRList")
    public PageInfo<Emr> selectEMRList(EMRVo emrVo){
        if(emrVo.getPageNum()==null||emrVo.getPageNum()==0){
            emrVo.setPageNum(1);
        }
        if(emrVo.getPageSize()==null||emrVo.getPageSize()==0){
            emrVo.setPageSize(10);
        }
        log.debug("接收到信息:{}",emrVo);
        PageInfo<Emr> pageInfo = emrService.selectEMRList(emrVo);
        return pageInfo;
    }

    /**
     * 根据ID查询详情
     * @param emrVo
     * @return
     */
    @PostMapping("/selectEMRDetail")
    public Emr selectEMRDetail(EMRVo emrVo){
        log.debug("接收到信息:{}",emrVo);
        Emr emr = emrService.selectEMRDetail(emrVo);
        return emr;
    }

    /**
     * 新增电子病历
     * @param emrVo
     * @return
     */
    @PostMapping("/addEMR")
    public String addEMR(EMRVo emrVo){
        log.debug("接收到信息:{}",emrVo);
        String res = emrService.addEMR(emrVo);
        return res;
    }
    /**
     * 修改电子病历
     * @param emrVo
     * @return
     */
    @PostMapping("/updateEMR")
    public String updateEMR(EMRVo emrVo){
        log.debug("接收到信息:{}",emrVo);
        String res = emrService.updateEMR(emrVo);
        return res;
    }
    /**
     * 删除电子病历
     * @param id
     * @return
     */
    @PostMapping("/deleteEMR/{id}")
    public String deleteEMR(@PathVariable Integer id){
        log.debug("接收到信息:{}",id);
        String res = emrService.deleteEMR(id);
        return res;
    }

}
